package com.aegean.CommercialHotelBookSystem.room.business.Impl;

import java.util.List;

import com.aegean.CommercialHotelBookSystem.factory.DaoFactory;
import com.aegean.CommercialHotelBookSystem.factory.MyTools;
import com.aegean.CommercialHotelBookSystem.hotel.dao.IHotelDao;
import com.aegean.CommercialHotelBookSystem.model.Hotel;
import com.aegean.CommercialHotelBookSystem.model.Room;
import com.aegean.CommercialHotelBookSystem.room.business.IRoomBusiness;
import com.aegean.CommercialHotelBookSystem.room.dao.IRoomDao;

public class RoomBusinessImpl implements IRoomBusiness {
	@Override
	public boolean searchReHotel(String name) {
		// TODO Auto-generated method stub
		IRoomDao dao = DaoFactory.createRoomDao();
		Hotel one = dao.searchHotel(name);
		if (one == null) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public boolean addRoom(String Hotel_Name, int Hotel_Id, String Room_Name,
			float Room_TotalMoney, float Room_Discount, int Room_Count,
			String Room_Type, String Room_Date) {
		Room one = null;
		try {
			one = new Room();
			one.setRoom_Name(Room_Name);
			one.setRoom_TotalMoney(Room_TotalMoney);
			one.setRoom_Count(Room_Count);
			one.setRoom_Discount(Room_Discount);
			one.setRoom_Type(Room_Type);
			one.setRoom_Date(MyTools.toDate(Room_Date));
			IRoomDao dao = DaoFactory.createRoomDao();
			boolean result = dao.addRoom(Hotel_Id, Hotel_Name, one);
			if (result == true) {
				return true;
			} else {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	@Override
	public List<Room> searchRoom(Hotel one, int intpage, int intpagesize,
			String bedType, String date) {
		IRoomDao hoteldao = DaoFactory.createRoomDao();
		List<Room> rooms = hoteldao.searchRoomList(one, intpage, intpagesize,
				bedType, date);
		return rooms;
	}

	@Override
	public int searchRoomCount(Hotel one, String bedType, String date,
			int intpagesize) {
		IRoomDao roomdao = DaoFactory.createRoomDao();
		int introwcount = roomdao.searchRoomListCount(one, bedType, date);
		int intpagecount = (introwcount + intpagesize - 1) / intpagesize;
		return intpagecount;
	}

	@Override
	public boolean updateRoom(int Room_Id, String Room_Name,
			float Room_TotalMoney, float Room_Discount, int Room_Count,
			String Room_Type, String Room_Date) {
		IRoomDao dao = DaoFactory.createRoomDao();
		boolean result = dao.updateRoom(Room_Id, Room_Name, Room_TotalMoney,
				Room_Discount, Room_Count, Room_Type, Room_Date);
		if (result == true) {
			return true;
		} else {
			return false;
		}
	}

	@Override
	public boolean deleteRoom(int Room_Id) {
		// TODO Auto-generated method stub
		IRoomDao dao = DaoFactory.createRoomDao();
		boolean result = dao.deleteRoom(Room_Id);
		if (result == true) {
			return true;
		} else {
			return false;
		}
	}
}
